program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  arr = array of integer;

var
  mass: array of arr;
  color: array of integer;
  n, i, j, sum: integer;

begin
  readln (n);
  setlength (mass, n, n);
  setlength (color, n);
  for i:= 0 to n-1 do
    for j:= 0 to n-1 do
      read (mass[i, j]);
  for i:= 0 to n-1 do
    read (color[i]);
  sum:= 0;
  for i:= 0 to n-1 do
    for j:= 0 to n-1 do
      if (mass[i, j]=1) then
        if (color[i]<>color[j]) then
          inc (sum);
  write (sum shr 1);
end.
